package com.kotasoft.training.roogwteclipselink.client.managed.ui;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.SpanElement;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Widget;

import com.kotasoft.training.roogwteclipselink.client.scaffold.place.ProxyDetailsView;
import com.kotasoft.training.roogwteclipselink.client.scaffold.place.ProxyListView;
import com.kotasoft.training.roogwteclipselink.client.managed.request.DireccionProxy;

/**
 * Details view for DireccionProxy.
 */
public class DireccionDetailsView extends Composite implements ProxyDetailsView<DireccionProxy> {
	interface Binder extends UiBinder<HTMLPanel, DireccionDetailsView> {}

	private static final Binder BINDER = GWT.create(Binder.class);

  private static DireccionDetailsView instance;

	DireccionProxy proxy;
	
	@UiField SpanElement id;
	@UiField SpanElement version;
	@UiField SpanElement tipoVia;
	@UiField SpanElement nombreVia;
	@UiField SpanElement numero;
	@UiField SpanElement ciudad;
	@UiField SpanElement cp;
	@UiField SpanElement provincia;
	@UiField SpanElement pais;	
	
	@UiField SpanElement displayRenderer;
	@UiField HasClickHandlers edit;
	@UiField HasClickHandlers delete;

	private Delegate delegate;

  public static DireccionDetailsView instance() {
    if (instance == null) {
      instance = new DireccionDetailsView();
    }
    
    return instance;
  }

	public DireccionDetailsView() {
		initWidget(BINDER.createAndBindUi(this));
	}

  	public Widget asWidget() {
		return this;
	}
  
	public boolean confirm(String msg) {
		return Window.confirm(msg);
	}

	public DireccionProxy getValue() {
		return proxy;
	}

	@UiHandler("delete")
	public void onDeleteClicked(ClickEvent e) {
		delegate.deleteClicked();
	}

	@UiHandler("edit")
	public void onEditClicked(ClickEvent e) {
		delegate.editClicked();
	}

	public void setDelegate(Delegate delegate) {
		this.delegate = delegate;
	}

	public void setValue(DireccionProxy proxy) {
		this.proxy = proxy;
		id.setInnerText(proxy.getId() == null ? "" : String.valueOf(proxy.getId()));
		version.setInnerText(proxy.getVersion() == null ? "" : String.valueOf(proxy.getVersion()));
		tipoVia.setInnerText(proxy.getTipoVia() == null ? "" : String.valueOf(proxy.getTipoVia()));
		nombreVia.setInnerText(proxy.getNombreVia() == null ? "" : String.valueOf(proxy.getNombreVia()));
		numero.setInnerText(proxy.getNumero() == null ? "" : String.valueOf(proxy.getNumero()));
		ciudad.setInnerText(proxy.getCiudad() == null ? "" : String.valueOf(proxy.getCiudad()));
		cp.setInnerText(proxy.getCp() == null ? "" : String.valueOf(proxy.getCp()));
		provincia.setInnerText(proxy.getProvincia() == null ? "" : String.valueOf(proxy.getProvincia()));
		pais.setInnerText(proxy.getPais() == null ? "" : String.valueOf(proxy.getPais()));

		displayRenderer.setInnerText(com.kotasoft.training.roogwteclipselink.client.managed.ui.DireccionProxyRenderer.instance().render(proxy));
	}
}
